package com.yt.util;

import java.util.Date;
import java.util.Random;

public class RandomUtil {
    public static String getRandomNumCode(int num) {
        String[] digits = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" };
        Random rnum = new Random(new Date().getTime());
        String returnStr = "";
        for (int i = 0; i < num; i++) {
            int index = Math.abs(rnum.nextInt()) % 10;
            returnStr +=digits[index];
        }
        return returnStr;
    }
    /**
     * 获取指定位数的随机数
     * @param length
     * @return
     * @author wuzl
     */
    public static long getRandom(int length){
        length=length-1;
        return (long)Math.pow(10, length)+(long)(Math.random()*(Math.pow(10, length+1)-Math.pow(10, length)));
    }
}

